﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Dynamic;
using Zhp.IService.Design;
using Zhp.Model.Common;
using Zhp.Model.Design;

namespace Zhp.Api.Controllers.Design
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DesignInstanceController : ControllerBase
    {
        private IDesignInstanceService _designInstanceService;
        public DesignInstanceController(IDesignInstanceService designInstanceService) 
        {
            _designInstanceService = designInstanceService;
        }

        [AllowAnonymous]
        [HttpGet("{listId}")]
        public async Task<DesignInstanceModel> QueryConfig(long listId)
        {
            return await _designInstanceService.QueryConfig(listId);
        }

        [AllowAnonymous]
        [HttpPost]
        public async Task<PageRet<object>> Query(DesignInstanceQuery query)
        {
            var list = await _designInstanceService.Query(query);
            return new PageRet<object>
            {
                DataList = list,
                TotalCount = query.TotalCount
            };
        }

        [AllowAnonymous]
        [HttpPost]
        public async Task<bool> Create(DesignInstanceEdit p)
        {
            return await _designInstanceService.Create(p);
        }

        [AllowAnonymous]
        [HttpPut]
        public async Task<bool> Update(DesignInstanceEdit p)
        {
            return await _designInstanceService.Update(p);
        }

        [AllowAnonymous]
        [HttpDelete("{formId}/{id}")]
        public async Task<bool> Delete(long formId, long id)
        {
            return await _designInstanceService.Delete(formId, id);
        }

        [AllowAnonymous]
        [HttpGet("{formId}/{id}")]
        public async Task<ExpandoObject> Details(long formId, long id)
        {
            return await _designInstanceService.Details(formId, id);
        }
    }
}
